﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Controls_GongQiu : System.Web.UI.UserControl
{
    string strSQL;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            left_down_ad();
            gongying();
            Buying();
        }
    }
    public void left_down_ad()
    {
        DataTable dt5 = Class1.ExecSel("select ad_Lock,ad_Url,ad_Img,ad_Location,ad_Time from AD where ad_Location=6 order by ad_ID desc");
        if (dt5.Rows[0]["ad_Lock"].ToString() == "0")
        {
            ad6.Text = "<a href=" + dt5.Rows[0]["ad_Url"].ToString() + " target=_blank><img src=" + dt5.Rows[0]["ad_Img"].ToString() + " border=0 width=279 height=116/></a>";
        }
        else
        {
            ad6.Text = "<img src=img/ad6.gif />";
        }
    }
    public void gongying()
    {
        strSQL = "select top 10 p_ID, case when len(p_Title)>7 then left(p_Title,7)+'' else p_Title end as p_Title,p_Type,p_Lock,p_Helpful,p_UserID from Product where p_Type='供应' and p_Lock=0  order by p_ID desc";
        SqlConnection conn = DB.getConnection();
        SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (ds.Tables[0].Rows[i]["p_Helpful"].ToString()=="1")
            {
                ds.Tables[0].Rows[i]["p_Title"] = "<b><font color=red>" + ds.Tables[0].Rows[i]["p_Title"].ToString() + "</font></b>";
            }
        }
        if (dt.Rows.Count > 0)
        {
            dl_Supply.DataSource = ds.Tables[0];
            dl_Supply.DataBind();
        }
        ds.Dispose();
        da.Dispose();

        conn.Close();
        conn.Dispose();
    }
    public void Buying()
    {
        strSQL = "select top 10 p_ID, case when len(p_Title)>7 then left(p_Title,7)+'' else p_Title end as p_Title,p_Type,p_Lock,p_Helpful,p_UserID from Product where p_Type='采购' and p_Lock=0 order by p_ID desc";
        SqlConnection conn = DB.getConnection();
        SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (ds.Tables[0].Rows[i]["p_Helpful"].ToString() == "1")
            {
                ds.Tables[0].Rows[i]["p_Title"] = "<b><font color=red>" + ds.Tables[0].Rows[i]["p_Title"].ToString() + "</font></b>";
            }
        }
        if (dt.Rows.Count > 0)
        {
            dl_Buying.DataSource = ds.Tables[0];
            dl_Buying.DataBind();
        }
        ds.Dispose();
        da.Dispose();
        conn.Close();
        conn.Dispose();
    }
}
